<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/4 0004
 * Time: 9:22
 */

namespace Cohuna\Services;

use Cohuna\Models\CohunaOrder;
use Cohuna\Models\CohunaOrderDetail;
use Cohuna\Paginator\PaginatorArray;

/**
 * 支付交易业务逻辑
 * @package Cohuna\Services
 */
class TransactionService extends ServiceBase
{
    const PageSize = 15;

    public function getOrderList($conditions,$page_index = 1,$page_size = 15,$url = '/transaction/list')
    {
        $offset = ($page_index - 1) * self::PageSize;


        $list = CohunaOrder::find(array(
            $conditions[0],
            'bind' => $conditions['bind'],
            'offset' => intval($offset),
            'limit' => $page_size
        ));
        $order_list = array();
        foreach ($list as $item){

            $order_list[] = CohunaOrder::getCohunaOrderExtendInfo($item);
        }

        $paginator = new PaginatorArray([
            'data'          => $order_list,
            'limit'         => self::PageSize,
            'current'          => $page_index,
            'total_items'   => CohunaOrder::count(array($conditions[0],'bind'=>$conditions['bind'])),
            'href'          => $url
        ]);
        return $paginator;
    }
}